/**
 * @description elem to html
 * @author wangfupeng
 */

import { SlateElement } from '@wangeditor/editor';
import { AttachmentElement } from './custom-types';

// 生成 html 的函数
function attachmentToHtml(elem: SlateElement, childrenHtml: string): string {
  const { link = '', fileName = '', size = 0 } = elem as AttachmentElement;
  const html = `<div data-w-e-type="link-card" data-w-e-is-void data-title="${fileName}" data-link="${link}">
  <div class="info-container">
    <div class="title-container"><p>${fileName}</p></div>
    <div class="link-container"><span>${link}</span></div>
  </div>
  <div class="icon-container">
  <div class="title-container"><p>${size}</p></div>
  </div>
</div>`;
  return html;
}

// 配置
const conf = {
  type: 'attachment', // 节点 type ，重要！！！
  elemToHtml: attachmentToHtml,
};

export default conf;
